<?php
namespace App\Controllers\Requests;
use App\Controllers\Base;


class Platform extends Base {
    private $db;
    function __construct() {
        $this->db = new \App\Models\Requests\Platform();
    }

    // 加载列表
    public function data(){
        if ( $err = $this->actionAuth(true) ) return $this->setError( $this->filed[$err] );
        $P = $this->U();
        $P['searchField'] = 'en_name,cn_name';
        $data = $this->db->search($P)->page($this->_page() , $this->_size(), true);

        return $this->toJson($data);
    }

    // 保存
    public function save(){
        $this->actionAuth();
        $P = $this->U();
        $this->db->setValidationMessages($this->db->validationMessages);
        if($this->db->save( $P )){
            return $this->toJson('保存成功');
        }else{
            return $this->setError($this->db->errors());
        }
    }

    // 删除
    public function delete(){
        if ( $err = $this->actionAuth(true) ) return $this->setError( $this->filed[$err] );
        if( $this->db->delete($this->U('id')) )
            return $this->toJson('已删除');
        return $this->setError('删除失败');
    }
}